package org.kotemaru.browser;
import org.kotemaru.util.IOUtil;
import java.io.*;
import org.apache.velocity.context.Context;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import org.apache.commons.beanutils.BeanUtils;

public class VelocityNavigator extends Navigator {
	private Action action;
	
	public VelocityNavigator(Action action, String rs) {
		super(rs);
		this.action = action;
	}

	public String getHtml() throws Exception {
		String name = getResource();
		String vm = IOUtil.getResource(action.getClass(), name);
		Context context = new VelocityContext(BeanUtils.describe(action));
		StringWriter sw = new StringWriter();
		Velocity.evaluate(context, sw, name, vm);
		return sw.toString();
	}
}
